/*
 * @Author: zhangjingyu
 * @Date: 2020-11-19 09:34:13
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-05-19 10:27:00
 * @FilePath: \vprisk10.14\vue.config.js
 * @Description: 
 */
const baseURL = require("./base.config")
const CSSSplitwebpackPlugin = require('css-split-webpack-plugin').default;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require("webpack")
module.exports = {
  publicPath: '/',
  assetsDir: "static",
  outputDir: "dist",
  lintOnSave: false, // ESlint开关
  productionSourceMap: false, // false: 生产环境取消source map
  transpileDependencies:['vue-contextmenujs','vue-tree-color'],
  devServer: {
    port: 8022,
    open: true,// 自动启动浏览器
    // 设置代理，使客户端通过服务器的方式与服务器通信，解决跨域问题
    proxy: {
      '/api': {
        // target: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_URL_PRODUCTION : process.env.VUE_APP_URL_DEVELOPMENT, // 代理服务器路径
        target:baseURL,
        changeOrigin: true,
        pathRewrite: {
            '^/api': '' // 去掉接口地址中的api字符串
        }
    }
    }
  },
  // css相关的配置
  css: {
    loaderOptions: {
      sass: {
        // 这里data换成 prependData  并且重启vue项目即可
        // 设置相对路径
        prependData: `@import "@/assets/scss/_variable.scss";`
      }
    }
  },
  chainWebpack: config => {
    // 其他配置
    config.entry('main').add('babel-polyfill'); // main是入口文件
    // 生产去除console
    config.when(process.env.NODE_ENV !== 'development', config => {
      config.optimization.minimizer('terser').tap(options => {
        options[0].terserOptions.compress.drop_console = true
        return options
      })
    });
  },
  configureWebpack: {
    plugins: [
      new CSSSplitwebpackPlugin({
        size: 4000,
        filename :'static/css/[name]-[part].[ext]'
      }),
      new MiniCssExtractPlugin({})
    ]
  }
  
}
